Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: message object fix #1302

Conversation

mohammeds1992
Copy link
Collaborator

Fixes Issue

Changes proposed

Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.

Screenshots

Note to reviewers

@mohammeds1992 mohammeds1992 requested a review from Aman035 May 21, 2024 16:03
@mohammeds1992 mohammeds1992 linked an issue May 21, 2024 that may be closed by this pull request
Copy link

  • In the mapToUpdateGroupEvent method, the code is incomplete and not correctly formatted. It seems like it is missing an argument for incomingData and includeRaw.

  • In the mapToMessageEvent method, there is a missing closing brace } after the reference: data.cid,.

  • In the handleChatEvent method, the closing brace } after the throw new Error('data is undefined or null'); is missing.

  • In the eventTypeMap object inside the handleChatEvent method, the last comma , after Reject: MessageEventType.Reject needs to be removed.

The corrected version of the code should address these issues.

...
  }

  public static mapToCreateGroupEvent(
    incomingData: any,
    includeRaw: boolean
  ): CreateGroupEvent {
    return this.mapToGroupEvent(
      GroupEventType.CreateGroup,
      incomingData,
      includeRaw
    ) as CreateGroupEvent;
  }

  public static mapToUpdateGroupEvent(
    incomingData: any,
    includeRaw: boolean
  ): UpdateGroupEvent {
    return this.mapToGroupEvent(
      GroupEventType.UpdateGroup,
      incomingData,
      includeRaw
    ) as UpdateGroupEvent;
  }

  public static mapToMessageEvent(
    data: any,
    includeRaw = false,
    eventType: MessageEventType
  ): MessageEvent {
    if (data.hasIntent === false && eventType === 'message') {
      eventType = MessageEventType.Request;
    }
    const messageEvent: MessageEvent = {
      event: eventType,
      origin: data.messageOrigin,
      timestamp: data.timestamp.toString(),
      chatId: data.chatId,
      from: data.fromCAIP10,
      to: [data.toCAIP10],
      message: {
        type: data.messageType,
        ...data.messageObj,
      },
      meta: {
        group: data.isGroup || false,
        reference: data.cid,
      }
    };
    if (includeRaw) {
      const rawData: MessageRawData = {
        fromCAIP10: data.fromCAIP10,
        toCAIP10: data.toCAIP10,
        fromDID: data.fromDID,
        toDID: data.toDID,
        encType: data.encType,
        encryptedSecret: data.encryptedSecret,
        signature: data.signature,
        sigType: data.sigType,
        verificationProof: data.verificationProof,
        previousReference: data.link,
      };
      messageEvent.raw = rawData;
    }
    return messageEvent;
  }

  public static handleChatEvent(data: any, includeRaw = false): any {
    if (!data) {
      console.error('Error in handleChatEvent: data is undefined or null');
      throw new Error('data is undefined or null');
    }
    const eventTypeMap: { [key: string]: MessageEventType } = {
      Chat: MessageEventType.Message,
      Request: MessageEventType.Request,
      Approve: MessageEventType.Accept,
      Reject: MessageEventType.Reject
    };
    const key = data.eventType || data.messageCategory;
...

After fixing these issues, the code looks good.

@mohammeds1992 mohammeds1992 merged commit 836e5c1 into main May 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

message contents is missing stream events for other types
2 participants